package yshttp

import (
	"context"
	"github.com/gogf/gf/v2/frame/g"
)

type HelloCommonReq struct {
	Name string `json:"name" dc:"你的名字" default:"我的朋友"`
}

type HelloGetReq struct {
	g.Meta `path:"/hello" tags:"欢迎信息" method:"get" summary:"欢迎信息 GET 调用"`
	HelloCommonReq
}

type HelloPostReq struct {
	g.Meta `path:"/hello" tags:"欢迎信息" method:"post" summary:"欢迎信息 POST 调用"`
	HelloCommonReq
}

type HelloPutReq struct {
	g.Meta `path:"/hello" tags:"欢迎信息" method:"put" summary:"欢迎信息 PUT 调用"`
	HelloCommonReq
}

type HelloDeleteReq struct {
	g.Meta `path:"/hello" tags:"欢迎信息" method:"delete" summary:"欢迎信息 DELETE 调用"`
	HelloCommonReq
}

type HelloRes struct {
	Message string `json:"message" dc:"欢迎信息" default:"Hello 我的朋友"`
}

func Hello() cHello {
	return cHello{}
}

type cHello struct {
}

func (c *cHello) HelloGet(ctx context.Context, req *HelloGetReq) (res *HelloRes, err error) {
	return helloControl(ctx, req.HelloCommonReq)
}

func (c *cHello) HelloPost(ctx context.Context, req *HelloPostReq) (res *HelloRes, err error) {
	return helloControl(ctx, req.HelloCommonReq)
}

func (c *cHello) HelloPut(ctx context.Context, req *HelloPutReq) (res *HelloRes, err error) {
	return helloControl(ctx, req.HelloCommonReq)
}

func (c *cHello) HelloDelete(ctx context.Context, req *HelloDeleteReq) (res *HelloRes, err error) {
	return helloControl(ctx, req.HelloCommonReq)
}

func helloControl(ctx context.Context, req HelloCommonReq) (res *HelloRes, err error) {
	out := helloLogic(ctx, helloInput{Name: req.Name})
	res = &HelloRes{
		Message: out.Message,
	}
	return
}

type helloInput struct {
	Name string
}

type helloOutput struct {
	Message string
}

func helloLogic(_ context.Context, in helloInput) (out *helloOutput) {
	return &helloOutput{Message: "Hello " + in.Name}
}
